---
title: Routing workflow
sidebarTitle: Routing
description: Classifies input and directs it to specialized follow-up tasks.
---

<Frame caption="Credits of the image to Anthropic">
  <img src="/assets/anthropic-building-agents/prompt-routing.webp" />
</Frame>

## Overview

Routing classifies an input and directs it to a specialized follow-up task. This workflow allows for separation of concerns and building more specialized prompts. Without this workflow, optimizing for one kind of input can hurt performance on other inputs.

The routing pattern works by having an initial classifier that determines what type of request or input it's dealing with, then routes it to the appropriate specialized handler. This enables you to create highly optimized prompts for each specific scenario rather than trying to handle all cases with a single, more generic prompt.

## When to use

Routing works well for complex tasks where there are distinct categories that are better handled separately, and where classification can be handled accurately, either by an LLM or a more traditional classification model/algorithm.

## Using prompt routing in Latitude

```markdown Customer Inquiry Routing
---
provider: openai
model: gpt-4o
temperature: 0.1
---

<step as="classification" schema={{
  type: "object",
  properties: {
    category: {
      type: "string",
      enum: ["general_inquiry", "refund_request", "technical_support", "billing_question", "product_info"],
      description: "The category of the customer inquiry"
    },
    confidence: {
      type: "number",
      minimum: 0,
      maximum: 1,
      description: "Confidence score for the classification"
    },
    reasoning: {
      type: "string",
      description: "Brief explanation for the classification"
    }
  },
  required: ["category", "confidence", "reasoning"]
}}>
  You are a customer service classifier. Analyze the customer inquiry and classify it into one of these categories:
  - general_inquiry: General questions about the company, policies, or services
  - refund_request: Customer wants to return a product or get a refund
  - technical_support: Technical issues with products or services
  - billing_question: Questions about charges, payments, or billing
  - product_info: Questions about specific products or features

  Classify the inquiry and provide your confidence level.

  <user>
    Customer inquiry: {{ customer_message }}
  </user>
</step>

{{ if classification.category == "general_inquiry" }}
  <step>
    You are a friendly general customer service representative. Provide helpful, accurate information about the company's policies and services. Keep responses warm and professional.

    <user>
      Customer inquiry: {{ customer_message }}
      Classification confidence: {{ classification.confidence }}
      Reasoning: {{ classification.reasoning }}

      Please provide a helpful response to this general inquiry.
    </user>
  </step>
{{ endif }}

{{ if classification.category == "refund_request" }}
  <step>
    You are a refund specialist. Guide customers through the refund process clearly and empathetically. Ask for necessary information like order number and reason for return.

    <user>
      Customer refund request: {{ customer_message }}
      Classification confidence: {{ classification.confidence }}

      Please help the customer with their refund request. Ask for order details if not provided.
    </user>
  </step>
{{ endif }}


{{ if classification.category == "technical_support" }}
<step>
    You are a technical support specialist. Provide step-by-step troubleshooting guidance. Ask clarifying questions about the issue and the customer's setup.

    <user>
      Technical support request: {{ customer_message }}
      Classification confidence: {{ classification.confidence }}

      Please provide technical assistance for this issue.
    </user>
  </step>
{{ endif }}

{{ if classification.category == "billing_question" }}
  <step>
    You are a billing specialist. Help customers understand their charges and payment options. Be clear about billing policies and next steps.

    <user>
    Billing inquiry: {{ customer_message }}
    Classification confidence: {{ classification.confidence }}

    Please assist with this billing question.
    </user>
  </step>
{{ endif }}

{{ if classification.category == "product_info" }}
  <step>
    You are a product specialist with deep knowledge of our product catalog. Provide detailed, accurate product information and help customers make informed decisions.

    <user>
      Product information request: {{ customer_message }}
      Classification confidence: {{ classification.confidence }}

      Please provide detailed product information to help the customer.
    </user>
  </step>
{{ endif }}
```

The routing pattern is particularly powerful when combined with other Latitude features like agents and tools, allowing you to create sophisticated systems that automatically adapt their behavior based on the type of input they receive.
